package model;

import java.awt.Color;
import java.awt.Polygon;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.Transient;

import control.Control;

@Entity(name = "Quadra")
public class Quadra {

	@Id
	@GeneratedValue
	private int id;

	@Column(name = "qnt_doentes", nullable = false)
	private int qntDoentes;

	@Column(name = "numero", nullable = false)
	private int numero;
	
	@OneToMany(fetch = FetchType.EAGER)
	@JoinColumn(name = "id_quadra")
	private List<Ponto> pontos;
	
	@Column(name = "point_paint_num_x", nullable = false)
	private int pointPaintNumX;
	
	@Column(name = "point_paint_num_y", nullable = false)
	private int pointPaintNumY;
	
	@Column(name = "reference_x", nullable = false)
	private int referenceX;
	
	@Column(name = "reference_y", nullable = false)
	private int referenceY;
	
	@Transient
	private int corValor;

	@Transient
	private Color cor;
	
	@Transient
	private Polygon polygon;

	public Quadra(int numero, int quantidadeDoentes, Polygon polygon, Color cor, int[] limitPoints, int refX, int refY) {
		this.numero = numero;
		this.qntDoentes = quantidadeDoentes;
		this.pointPaintNumX = limitPoints[0];
		this.pointPaintNumY = limitPoints[1];
		this.cor = cor;
		this.polygon = polygon;
		this.referenceX = refX;
		this.referenceY = refY;
		this.pontos = new ArrayList<Ponto>();
		for (int i = 0; i < polygon.npoints; i++) {
			this.pontos.add(new Ponto(polygon.xpoints[i], polygon.ypoints[i]));
		}
		Control.getInstance().getPointToPaintNumber(this);
	}
	
	public Quadra() {
	}
	
	public int getNumero() {
		return numero;
	}
	
	public void setPointToPaintNumber(int[] pointToPaintNumber) {
		pointPaintNumX = pointToPaintNumber[0];
		pointPaintNumX = pointToPaintNumber[1];
	}
	
	public Color getCor() {
		return cor;
	}

	public void setCor(Color cor) {
		this.cor = cor;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public int getCorValor() {
		return corValor;
	}

	public void setCorValor(int corValor) {
		this.corValor = corValor;
	}

	public void setNumero(int numero) {
		this.numero = numero;
	}

	public int getQntDoentes() {
		return qntDoentes;
	}

	public void setQntDoentes(int qntDoentes) {
		this.qntDoentes = qntDoentes;
	}

	public List<Ponto> getPontos() {
		return pontos;
	}

	public void setPontos(List<Ponto> pontos) {
		this.pontos = pontos;
	}

	public int getPointPaintNumX() {
		return pointPaintNumX;
	}

	public int getPointPaintNumY() {
		return pointPaintNumY;
	}

	public Polygon getPolygon() {
		return polygon;
	}

	public void setPolygon(Polygon polygon) {
		this.polygon = polygon;
	}

	public int getReferenceX() {
		return referenceX;
	}

	public void setReferenceX(int referenceX) {
		this.referenceX = referenceX;
	}

	public int getReferenceY() {
		return referenceY;
	}

	public void setReferenceY(int referenceY) {
		this.referenceY = referenceY;
	}
	
}
